package com.itheima.exerciseTest.method40_49.method41;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Test69 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        // 创建系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

        // 读取配置文件
        InputStream is = systemClassLoader.getResourceAsStream("prop1.properties");

        // 将读取到的信息保存在集合中
        Properties prop = new Properties();
        prop.load(is);
        is.close();
        System.out.println(prop);

        // 获得Class对象
        Class className = Class.forName(prop.getProperty("className"));

        // 创建对象
        Person o = (Person) className.newInstance();

        // 获取Method对象
        Method method = className.getDeclaredMethod(prop.getProperty("methodName"));

        // 使用方法
        method.invoke(o);


    }
}
